/**
 * Candidate number: 35834
 */
package tv.starfu.animae;

import com.artemis.Entity;
import com.artemis.World;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.terrain.geomipmap.TerrainGrid;
import com.jme3.terrain.geomipmap.TerrainGridListener;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.geomipmap.grid.FractalTileLoader;
import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
import com.jme3.terrain.heightmap.AbstractHeightMap;
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.terrain.noise.ShaderUtils;
import com.jme3.terrain.noise.basis.FilteredBasis;
import com.jme3.terrain.noise.filter.IterativeFilter;
import com.jme3.terrain.noise.filter.OptimizedErode;
import com.jme3.terrain.noise.filter.PerturbFilter;
import com.jme3.terrain.noise.filter.SmoothFilter;
import com.jme3.terrain.noise.fractal.FractalSum;
import com.jme3.terrain.noise.modulator.NoiseModulator;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;

public class RaceTrack extends Anima {

    private BulletAppState bullet;
    private AssetManager assetManager;
    private Node starRaceTrack = new Node("starRaceTrackNode");
    private Node level;

    public Node getStarRaceTrack() {
        return starRaceTrack;
    }

    public void setStarRaceTrack(Node starRaceTrack) {
        this.starRaceTrack = starRaceTrack;
    }
    
    public RaceTrack(World world, Entity owner, SimpleApplication app, Node root) {
        super(world, owner, app);
        this.level = root;
        this.bullet = app.getStateManager().getState(BulletAppState.class);
        this.assetManager = app.getAssetManager();
    }
    
    @Override
    public void initalize() {
        Spatial scene = assetManager.loadModel("Scenes/tropicalypso.j3o");
        
        scene.setLocalScale(2f);
        
        CollisionShape matTer = CollisionShapeFactory.createMeshShape(scene);
        RigidBodyControl track = new RigidBodyControl(0f);
        
        scene.addControl(track);
        track.setCollisionShape(matTer);
        
        bullet.getPhysicsSpace().add(track);
        track.setPhysicsLocation(new Vector3f(0, 0, 0));
        
        starRaceTrack.attachChild(scene);
        
        level.attachChild(starRaceTrack);
        //app.getRootNode().attachChild(starRaceTrack);
        
    }

    @Override
    public void render() {
       // throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
